USE Liberty
GO
-- ------------------------------------------------------------------------------------------------
-- GrantEvents create table script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating GrantEvents table...'
GO

IF OBJECT_ID( 'GrantEvents' ) IS NULL
BEGIN
    CREATE TABLE dbo.GrantEvents 
	(OID						bigint		IDENTITY(1, 1)	NOT NULL
	,Version					rowversion
	,GrantID					bigint						NOT NULL
	,ActivityID					bigint						NOT NULL 
	,UserID						bigint						NOT NULL 
	,EventOccurred				datetime					NOT NULL
		CONSTRAINT DFLT_GrantEvents_EventTime DEFAULT GETDATE()
	,EventNotes					varchar(MAX)					NULL

	,CONSTRAINT PK_GrantEvents PRIMARY KEY CLUSTERED (OID)

	,CONSTRAINT FK_GrantEvents_Grants FOREIGN KEY (GrantID)
		REFERENCES DBO.Grants(OID)

	,CONSTRAINT FK_GrantEvents_TypeOfActivity FOREIGN KEY (ActivityID) 
		REFERENCES DBO.TypesOfActivity(OID)

	,CONSTRAINT FK_GrantEvents_Users FOREIGN KEY (UserID)
		REFERENCES DBO.Users(OID)

	)
	PRINT 'GrantEvents table has been created...'
END
ELSE
BEGIN
	PRINT 'GrantEvents table already exists'
END
GO

